package thread;


public class RunnableExample {
    public static void main(String[] args) {
        // 创建两个Runnable任务对象
        Runnable task1 = new MyRunnable("任务1");
        Runnable task2 = new MyRunnable("任务2");

        // 创建Thread对象并传入Runnable任务
        Thread thread1 = new Thread(task1);
        Thread thread2 = new Thread(task2);

        System.out.println("启动线程...");

        // 启动线程
        thread1.start();
        thread2.start();

        try {
            // 等待两个线程都结束
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            System.out.println("主线程被中断");
        }

        System.out.println("主线程退出");
    }
}